package com.sx.pipeline.ui.workbench.frag

import android.app.Application
import com.sx.mvvmlibs.base.BaseViewModel
import com.sx.mvvmlibs.event.SingleLiveEvent
import com.sx.mvvmlibs.http.CommonObserver
import com.sx.mvvmlibs.utils.Logs
import com.sx.mvvmlibs.utils.RxThreadHelper
import com.sx.pipeline.R
import com.sx.pipeline.app.model.CYBaseViewModel
import com.sx.pipeline.repos.http.res.Ipage
import com.sx.pipeline.repos.http.res.ReleaseTaskVo
import com.sx.pipeline.repos.http.res.TaskStatisticsVO

/**
 * @Author: YY
 * @Date: 2022/4/13
 * @Description: TODO
 */
class TaskVM(app: Application): CYBaseViewModel(app) {

    /**
     * 获取 Tab标题
     */
    fun getTaskTabsList(releaseNum: Int, partakeNum: Int, examine: Int): List<String> {
        val tabs = mutableListOf<String>()
        tabs.add("$releaseNum \n发布的任务")
        tabs.add("$partakeNum \n参与的任务")
        tabs.add("$examine \n审批的任务")
        return tabs
    }


    /**
     * 获取任务统计数据
     */

    val taskStatisticsEvent: SingleLiveEvent<HashMap<Int, TaskStatisticsVO>> = SingleLiveEvent()

    fun getTaskStatisticsData(taskType: Int, timeType: Int) {
        addSubscribe(
            mModel.getTaskStatistics(taskType, timeType)
                .compose(RxThreadHelper.rxSchedulerHelper())
                .subscribeWith(object : CommonObserver<HashMap<Int, TaskStatisticsVO>, BaseViewModel<*>>
                    (this, false) {
                    override fun onResult(result: HashMap<Int, TaskStatisticsVO>) {
                        taskStatisticsEvent.postValue(result)
                    }
                })
        )
    }

    /**
     * 获取未完成任务列表
     */
    val undoneTaskEvent: SingleLiveEvent<Ipage<ReleaseTaskVo>> = SingleLiveEvent()

    fun getUndoneTask() {
        mModel.getUndoneTask(0,0, 0,true,1, 2)
            .compose(RxThreadHelper.rxSchedulerHelper())
            .subscribeWith(object : CommonObserver<Ipage<ReleaseTaskVo>, BaseViewModel<*>>
                (this, false) {
                override fun onResult(result: Ipage<ReleaseTaskVo>) {
                    // Logs.d("onResult: ${result.records.size}")
                    undoneTaskEvent.postValue(result)
                }
            })
    }
}